<!--
 * @Author: your name
 * @Date: 2021-12-07 09:21:15
 * @LastEditTime: 2021-12-07 10:16:43
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \toutiao-m\src\views\User\components\UserEditSex.vue
-->

<template>
  <div>
    <van-picker
      title="更新性别"
      show-toolbar
      :default-index="value"
      :columns="columns"
      @confirm="onConfirm"
      @cancel="$emit('close')"
    />
  </div>
</template>

<script>
import { UpdateUserProfile } from '@/api/user.js'
import { Toast } from 'vant'
export default {
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  data () {
    return {
      columns: ['男', '女']
    }
  },

  created () {},

  methods: {
    async onConfirm (val, index) {
      try {
        await UpdateUserProfile({
          gender: index
        })
        this.$emit('close')
        this.$emit('input', index)
        Toast.success('更新成功！')
      } catch (error) {
        Toast.success('更新失败！！')
      }
    }
  }
}
</script>

<style scoped lang="less"></style>
